<template>
  <!-- 侧边栏菜单区 -->
  <el-aside :width="isCollapse ? '64px' : '200px'">
    <div class="menu-hide" @click="toggleHide">|||</div>
    <el-menu
      background-color="#313743"
      text-color="#fff"
      active-text-color="#409eff"
      unique-opened
      :collapse="isCollapse"
      :collapse-transition="false"
      router
      :default-active="activePath"
    >
      <el-submenu :index="item.id + ''" v-for="item in menuList" :key="item.id">
        <!-- 模板 -->
        <template slot="title">
          <i :class="iconsObj[item.id]"></i>
          <span>{{ item.authName }}</span>
        </template>
        <el-menu-item
          :index="'/' + itemChildren.path"
          v-for="itemChildren in item.children"
          :key="itemChildren.id"
          @click="getactivePath('/' + itemChildren.path)"
        >
          <template slot="title">
            <i class="el-icon-menu"></i>
            <span>{{ itemChildren.authName }}</span>
          </template>
        </el-menu-item>
      </el-submenu>
    </el-menu>
  </el-aside>
</template>

<script>
export default {
  name: 'HomeSide',
  props: {
    menuList: {
      type: Array,
      default() {
        return []
      },
    },
    iconsObj: {
      type: Object,
      default() {
        return {}
      },
    },
  },
  data() {
    return {
      isCollapse: false,
      activePath: '',
    }
  },
  methods: {
    //侧边菜单缩小
    toggleHide() {
      this.isCollapse = !this.isCollapse
    },
    getactivePath(active) {
      window.sessionStorage.setItem('activePath', active)
      this.activePath = active
    },
  },
  created() {
    this.activePath = window.sessionStorage.getItem('activePath')
  },
}
</script>

<style lang="less" scoped>
.el-aside {
  background-color: #313743;
  .iconfont {
    margin-right: 10px;
  }
  .el-menu {
    border-right: none;
  }
}
.menu-hide {
  background-color: #475163;
  color: #fff;
  text-align: center;
  cursor: pointer;
}
</style>